<template>
  <div class="search">
    <f-form ref="form" :action="api.material" :form-key="this.formItem.materialId">
      <f-form-item label="项目" type="select" name="projectId" :showSearch="true"
                   :data="api.material.projectList" label-key="projectName" value-key="projectId"
                   :value="formItem.projectId" :disabled="true"/>
      <f-form-item label="工程包代码" name="packageNo" :required="true" :value="formItem.packageNo"/>
      <f-form-item label="工程包名称" name="packageName" :required="true" :value="formItem.packageName"/>
      <f-form-item label="专业代码" name="majorCode" :required="true" :value="formItem.majorCode"/>
      <f-form-item label="专业包名称" name="majorName" :required="true" :value="formItem.majorName"/>
<!--      <f-form-item label="服务代码" name="serviceCode" ref="serviceCode" :required="isRequired1"-->
<!--                   :value="formItem.serviceCode" @change="inputChange" v-if="show1"/>-->
<!--      <f-form-item label="服务WBS代码" name="serviceWbsCode" ref="serviceWbsCode" :required="isRequired1"-->
<!--                   :value="formItem.serviceWbsCode" @change="inputChange" v-if="show1"/>-->
      <f-form-item label="服务代码" type="pageSelect" name="serviceCode" :required="isRequired1"  :showSearch="true"
                   :data="api.service.page" label-key="serviceCode" value-key="serviceCode"
                   :value="formItem.serviceCode" :params="{}"  @change="inputChange(this.value,'serviceCode')" />
      <f-form-item label="服务WBS代码" type="pageSelect" name="serviceWbsCode" :required="isRequired1" :showSearch="true"
                   :data="api.wbsarchitecture.page" label-key="wbsCode" value-key="wbsCode"
                   :value="formItem.serviceWbsCode" :params="{}"  @change="inputChange" />
<!--      <f-form-item label="全物料代码" name="materialCode" ref="materialCode" :required="isRequired2"-->
<!--                   :value="formItem.materialCode" v-if="show2&&loaded" @change="inputChange"/>-->
      <f-form-item label="全物料代码" type="pageSelect" name="materialCode" :required="isRequired2":showSearch="true"
                   :data="api.materialserice.page" label-key="materialCode" value-key="materialCode"
                   :value="formItem.materialCode" :params="{}"   @change="inputChange"  />
<!--      <f-form-item label="材料WBS代码" name="materialWbsCode" ref="materialWbsCode" :required="isRequired2"-->
<!--                   :value="formItem.materialWbsCode" v-if="show2&&loaded" @change="inputChange"/>-->
      <f-form-item label="材料WBS代码" type="pageSelect" name="materialWbsCode" :showSearch="true"
                   :data="api.wbsarchitecture.page" label-key="wbsCode" :required="isRequired2" value-key="wbsCode"
                   :value="formItem.materialWbsCode"    :params="{}" @change="inputChange"  />
      <!-- <f-form-item label="型号/规格" name="materiaSpecs" ref="materiaSpecs" v-if="show2&&loaded" :required="isRequired2"
                   :value="formItem.materiaSpecs"/> -->
      <f-form-item label="项目名称" name="materiaSpecs" ref="materiaSpecs" v-if="show2&&loaded" :required="isRequired2"
                   :value="formItem.materiaSpecs"/>
      <f-form-item label="技术参数说明" name="technicalData" ref="technicalData" v-if="show2&&loaded" :required="isRequired2"
                   :value="formItem.technicalData"/>
      <f-form-item label="材料项目描述" name="materialDesc" ref="materialDesc" v-if="show2&&loaded" :required="isRequired2"
                   :value="formItem.materialDesc"/>
      <f-form-item label="设备材料名称" name="materialName" ref="materialName" v-if="show2&&loaded" :required="isRequired2"
                   :value="formItem.materialName"/>
      <f-form-item label="科目名称" name="subjectName" :required="true" :value="formItem.subjectName"/>
      <f-form-item label="层级号" name="levelNo" :required="true" :value="formItem.levelNo"/>
      <f-form-item label="分承包发包项目描述" name="packageDesc" ref="packageDesc" v-if="show1" :required="isRequired1"
                   :value="formItem.packageDesc"/>
      <f-form-item label="对外合同描述" name="contractDesc" :value="formItem.contractDesc"/>
      <f-form-item label="区域" name="materialArea" :required="true" :value="formItem.materialArea"/>
      <f-form-item label="系统" name="materialUse" :required="true" :value="formItem.materialUse"/>
      <f-form-item label="换算单位" name="conversionUnit" :required="true" :value="formItem.conversionUnit"/>
      <f-form-item label="计量单位" name="measurementUnit" :required="true" :value="formItem.measurementUnit"/>
      <f-form-item label="标前工程量" name="beforeMarkQuantity" :validator="validatedecimal1" type="number"
                   data-type="number" required="true"
                   :value="formItem.beforeMarkQuantity"/>
      <f-form-item label="品牌" name="brandName" :validator="validatedecimal1"  :required="isRequired2"
                   :value="formItem.brandName"/>
      <f-form-item label="备注" name="remark" :validator="validatedecimal1"  :required="isRequired2"
                  :value="formItem.remark"/>
      <f-form-item label="合同清单工程量" name="contractBillQuantity" type="number" required="true" data-type="number"
                   :validator="validatedecimal2"
                   :value="formItem.contractBillQuantity"/>
      <f-form-item label="损耗" name="loss" :disabled="disabled" v-if="formItem.loss==''" type="number" data-type="number"
                   :validator="validatedecimal3"
                   :required="true" :value="formItem.loss"/>
      <f-form-item label="损耗" name="loss" :disabled="true" v-if="formItem.loss!=''" type="number" data-type="number"
                   :value="formItem.loss"/>
      <f-form-item label="成本主材价" name="mainPrice" :validator="validatedecimal4" type="number" data-type="number"
                   v-if="show2 &&loaded" :required="isRequired2" :value="formItem.mainPrice"/>
      <!--      <f-form-item label="成本主材价" name="mainPrice" :validator="validatedecimal4" :required="isRequired2"   :disabled="true"-->
      <!--                   v-if="formItem.mainPrice!=''" :value="formItem.mainPrice"/>-->

      <f-form-item label="有合同主材价" name="mainPrice1" v-if="show2&&loaded" type="number" data-type="number"
                   :required="isRequired2" :value="formItem.mainPrice1"/>

      <!--      <f-form-item label="有合同主材价" name="mainPrice1" :disabled="true":required="isRequired2"   v-if="formItem.mainPrice1!=''"-->
      <!--                   :validator="validatedecimal5" :value="formItem.mainPrice1"/>-->

      <f-form-item label="拟合同主材价" name="mainPrice2" :required="isRequired2" type="number" v-if="show2&&loaded"
                   data-type="number" :validator="validatedecimal6" :value="formItem.mainPrice2"/>

      <!--      <f-form-item label="拟合同主材价" name="mainPrice2" :required="isRequired2"  :disabled="true" v-if="formItem.mainPrice2!=''"-->
      <!--                   :validator="validatedecimal6" :value="formItem.mainPrice2"/>-->

      <f-form-item label="成本安装价" name="installPrice" v-if="show1" :required="isRequired1" type="number"
                   data-type="number" :validator="validatedecimal7" :value="formItem.installPrice"/>

      <!--      <f-form-item label="成本安装价" name="installPrice" :required="isRequired1"  :disabled="true" v-if="formItem.installPrice!=''"-->
      <!--                   :validator="validatedecimal7" :value="formItem.installPrice"/>-->

      <f-form-item label="有合同安装价" name="installPrice1" v-if="show1" :required="isRequired1" type="number"
                   data-type="number" :validator="validatedecimal8" :value="formItem.installPrice1"/>

      <!--      <f-form-item label="有合同安装价" name="installPrice1" :required="isRequired1"  :disabled="true" v-if="formItem.installPrice1!=''"-->
      <!--                   :validator="validatedecimal8" :value="formItem.installPrice1"/>-->

      <f-form-item label="拟合同安装价" name="installPrice2" v-if="show1" :required="isRequired1" type="number"
                   data-type="number" :validator="validatedecimal9" :value="formItem.installPrice2"/>

      <!--      <f-form-item label="拟合同安装价" name="installPrice2" :required="isRequired1" :disabled="true" v-if="formItem.installPrice2!=''"-->
      <!--                   :validator="validatedecimal9" :value="formItem.installPrice2"/>-->

<!--      <f-form-item label="100预算成本工程量" name="costQuantity100" :disabled="disabled" v-if="formItem.costQuantity100==''"-->
<!--                   :required="true" :validator="validatedecimal10" :value="formItem.costQuantity100"/>-->
<!--      <f-form-item label="100预算成本工程量" name="costQuantity100" :disabled="true" v-if="formItem.costQuantity100!=''"-->
<!--                   :validator="validatedecimal10" :value="formItem.costQuantity100"/>-->
      <f-form-item label="100预算成本工程量" name="costQuantity100" data-type="number"  type="number" :validator="validatedecimal10" :value="formItem.costQuantity100"/>
      <f-form-item label="200预算成本工程量" name="costQuantity200"  data-type="number"  type="number"  :value="formItem.costQuantity200"/>
    </f-form>
  </div>
</template>
<script>
  import api from './js/api'
  import apiOther from './js/apiOther'
  export default {
    name: 'bmpForm',
    props: {
      projectId: {
        type: String,
        default: ''
      }
    },
    data() {
      return {
        refs: this.$refs,
        api: Object.assign(api, apiOther, this.api),
        isAdd: true,//是否是添加模式
        loaded: false,//是否加载完成
        formItem: this.getFormItem(),
        disabled: false,
        flag: true,
        isRequired1: false,
        show1: true,
        show2: true,
        isRequired2: false
      }
    },
    methods: {
      getFormItem() {
        return {
          materialId: '',
          parentId: '',
          projectId: '',
          materialWbsCode: '',
          materialCode: '',
          conversionUnit: '',
          syntheticalPrice: '',
          syntheticalPrice1: '',
          syntheticalPrice2: '',
          syntheticalPrice3: '',
          syntheticalAmount: '',
          syntheticalAmount1: '',
          syntheticalAmount2: '',
          syntheticalAmount3: '',
          otherPrice: '',
          otherAmount: '',
          beforeMarkQuantity: '',
          contractBillQuantity: '',
          measurementUnit: '',
          // materiaSpecs: '',
          materiaSpecs: '',
          technicalData: '',
          contractDesc: '',
          loss: '',
          mainPrice: '',
          mainPrice1: '',
          mainPrice2: '',
          mainPrice3: '',
          mainsumPrice1: '',
          mainsumPrice2: '',
          mainsumPrice3: '',
          mainAmount: '',
          mainAmount1: '',
          mainAmount2: '',
          mainAmount3: '',
          installPrice: '',
          installPrice1: '',
          installPrice2: '',
          installPrice3: '',
          installsumPrice1: '',
          installsumPrice2: '',
          installsumPrice3: '',
          installAmount: '',
          installAmount1: '',
          installAmount2: '',
          installAmount3: '',
          contractSyntheticalPrice1: '',
          contractSyntheticalPrice2: '',
          contractSyntheticalPrice3: '',
          contractsumSyntheticalPrice1: '',
          contractsumSyntheticalPrice2: '',
          contractsumSyntheticalPrice3: '',
          unitBillQuantity100: '',
          convertBillQuantity100: '',
          unitBillQuantity200: '',
          convertBillQuantity200: '',
          planPurchaseCount: '',
          convertPurchaseCount: '',
          currentFinishMonthCount: '',
          lastFinishMonthCount: '',
          totalFinishCount: '',
          packageNo: '',
          packageName: '',
          majorCode: '',
          majorName: '',
          serviceCode: '',
          serviceWbsCode: '',
          subjectName: '',
          levelNo: '',
          packageDesc: '',
          materialDesc: '',
          materialArea: '',
          materialUse: '',
          costQuantity100: '',
          costQuantity200: '',
          contractInstallPrice1: '',
          contractInstallPrice2: '',
          contractInstallPrice3: '',
          contractOtherPrice1: '',
          contractOtherPrice2: '',
          contractOtherPrice3: '',
          status: ''
        }
      },
      //表单赋值
      setData(data, info) {
        this.$refs.form.resetFields()
        this.formItem = this.getFormItem()
        if (data && data.materialPlanId) {
          let params = {
            materialPlanId: data.materialPlanId
          }
          this.refs['form'].getDetails(params, (data) => {
            this.formItem = data
            if (!data.serviceCode) {
              this.isRequired1 = false
              this.isRequired2 = true
              this.show2 = true
              this.show1 = false
            } else {
              this.isRequired1 = true
              this.isRequired2 = false
              this.show2 = false
              this.show1 = true
            }
            this.loaded = true
          })
          this.isAdd = false
        } else {
          this.formItem.projectId = info.projectId
          this.loaded = true
        }
      },
      validatedecimal1(rule, value, callback) {
        debugger
        const form = this.$refs.form.getForm()
        if (value) {
          form.validateFields(['beforeMarkQuantity'], { force: 'change' })
        }
        callback()
      },
      validatedecimal2(rule, value, callback) {
        const form = this.$refs.form.getForm()
        if (value) {
          form.validateFields(['contractBillQuantity'], { force: 'change' })
        }
        callback()
      },
      validatedecimal3(rule, value, callback) {
        const form = this.$refs.form.getForm()
        if (value) {
          form.validateFields(['loss'], { force: 'change' })
        }
        callback()
      },
      validatedecimal4(rule, value, callback) {
        const form = this.$refs.form.getForm()
        if (value) {
          form.validateFields(['mainPrice'], { force: 'change' })
        }
        callback()
      },
      validatedecimal5(rule, value, callback) {
        const form = this.$refs.form.getForm()
        if (value) {
          form.validateFields(['mainPrice1'], { force: 'change' })
        }
        callback()
      },
      validatedecimal6(rule, value, callback) {
        const form = this.$refs.form.getForm()
        if (value) {
          form.validateFields(['mainPrice2'], { force: 'change' })
        }
        callback()
      },
      validatedecimal7(rule, value, callback) {
        const form = this.$refs.form.getForm()
        if (value) {
          form.validateFields(['installPrice'], { force: 'change' })
        }
        callback()
      },
      validatedecimal8(rule, value, callback) {
        const form = this.$refs.form.getForm()
        if (value) {
          form.validateFields(['installPrice1'], { force: 'change' })
        }
        callback()
      },
      validatedecimal9(rule, value, callback) {
        const form = this.$refs.form.getForm()
        if (value) {
          form.validateFields(['installPrice2'], { force: 'change' })
        }
        callback()
      },
      validatedecimal10(rule, value, callback) {
        const form = this.$refs.form.getForm()
        if (value) {
          form.validateFields(['costQuantity100'], { force: 'change' })
        }
        callback()
      },
      //提交表单
      handleSubmit(callback) {
        this.$refs.form.submit({ handlerName: 'materialPlan100SaveHandler' }, callback)
      },
      inputChange(value, id) {
        if (id == 'serviceCode') {
          if (value) {
            this.isRequired1 = true
            this.isRequired2 = false
            this.show2 = false
          } else {
            this.isRequired1 = false
            this.isRequired2 = true
            this.show2 = true
          }
        }
      }
    },
    created() {
    },
    components: {}
  }
</script>

<style scoped lang="less" rel="stylesheet/less">

</style>
